package com.chezhujie.www.service;


import com.chezhujie.www.domain.Czjweixinvoucher;
import com.chezhujie.www.persistence.CzjweixinvoucherMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.core.page.Pagination;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 微信支付凭证
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjweixinvoucherService extends BaseService<Czjweixinvoucher> {
    @Autowired
    private CzjweixinvoucherMapper czjweixinvoucherMapper;

    @Autowired
    public void setBaseMapper(CzjweixinvoucherMapper czjweixinvoucherMapper) {
        this.baseMapper = czjweixinvoucherMapper;
    }


    public void checkEntity(Czjweixinvoucher czjweixinvoucher) throws ClassCheckException {
        if(czjweixinvoucher.getAppid()!=null&&czjweixinvoucher.getAppid().length()>32){
            throw new ClassCheckException("微信支付凭证公众账号ID不能超过32个字符");
        }
        if(czjweixinvoucher.getMch_id()!=null&&czjweixinvoucher.getMch_id().length()>32){
            throw new ClassCheckException("微信支付凭证商户号不能超过32个字符");
        }
        if(czjweixinvoucher.getDevice_info()!=null&&czjweixinvoucher.getDevice_info().length()>32){
            throw new ClassCheckException("微信支付凭证设备号不能超过32个字符");
        }
        if(czjweixinvoucher.getNonce_str()!=null&&czjweixinvoucher.getNonce_str().length()>32){
            throw new ClassCheckException("微信支付凭证随机字符串不能超过32个字符");
        }
        if(czjweixinvoucher.getSign()!=null&&czjweixinvoucher.getSign().length()>32){
            throw new ClassCheckException("微信支付凭证签名不能超过32个字符");
        }
        if(czjweixinvoucher.getSign_type()!=null&&czjweixinvoucher.getSign_type().length()>32){
            throw new ClassCheckException("微信支付凭证签名类型不能超过32个字符");
        }
        if(czjweixinvoucher.getResult_code()!=null&&czjweixinvoucher.getResult_code().length()>16){
            throw new ClassCheckException("微信支付凭证业务结果不能超过16个字符");
        }
        if(czjweixinvoucher.getErr_code()!=null&&czjweixinvoucher.getErr_code().length()>32){
            throw new ClassCheckException("微信支付凭证错误代码不能超过32个字符");
        }
        if(czjweixinvoucher.getErr_code_des()!=null&&czjweixinvoucher.getErr_code_des().length()>128){
            throw new ClassCheckException("微信支付凭证错误代码描述不能超过128个字符");
        }
        if(czjweixinvoucher.getOpenid()!=null&&czjweixinvoucher.getOpenid().length()>128){
            throw new ClassCheckException("微信支付凭证用户标识不能超过128个字符");
        }
        if(czjweixinvoucher.getIs_subscribe()!=null&&czjweixinvoucher.getIs_subscribe().length()>1){
            throw new ClassCheckException("微信支付凭证是否关注公众账号不能超过1个字符");
        }
        if(czjweixinvoucher.getTrade_type()!=null&&czjweixinvoucher.getTrade_type().length()>16){
            throw new ClassCheckException("微信支付凭证交易类型不能超过16个字符");
        }
        if(czjweixinvoucher.getBank_type()!=null&&czjweixinvoucher.getBank_type().length()>16){
            throw new ClassCheckException("微信支付凭证付款银行不能超过16个字符");
        }
        if(czjweixinvoucher.getFee_type()!=null&&czjweixinvoucher.getFee_type().length()>8){
            throw new ClassCheckException("微信支付凭证货币种类不能超过8个字符");
        }
        if(czjweixinvoucher.getCash_fee_type()!=null&&czjweixinvoucher.getCash_fee_type().length()>16){
            throw new ClassCheckException("微信支付凭证现金支付货币类型不能超过16个字符");
        }
        if(czjweixinvoucher.getCoupon_id_n()!=null&&czjweixinvoucher.getCoupon_id_n().length()>20){
            throw new ClassCheckException("微信支付凭证代金券ID不能超过20个字符");
        }
        if(czjweixinvoucher.getTransaction_id()!=null&&czjweixinvoucher.getTransaction_id().length()>32){
            throw new ClassCheckException("微信支付凭证微信支付订单号不能超过32个字符");
        }
        if(czjweixinvoucher.getOut_trade_no()!=null&&czjweixinvoucher.getOut_trade_no().length()>32){
            throw new ClassCheckException("微信支付凭证商户订单号不能超过32个字符");
        }
        if(czjweixinvoucher.getAttach()!=null&&czjweixinvoucher.getAttach().length()>128){
            throw new ClassCheckException("微信支付凭证商家数据包不能超过128个字符");
        }
        if(czjweixinvoucher.getTime_end()!=null&&czjweixinvoucher.getTime_end().length()>14){
            throw new ClassCheckException("微信支付凭证支付完成时间不能超过14个字符");
        }
    }
    public void checkListEntity(List<Czjweixinvoucher> listCzjweixinvoucher) throws ClassCheckException {

        for (Czjweixinvoucher czjweixinvoucher : listCzjweixinvoucher) {
            checkEntity(czjweixinvoucher);
        }

    }


	public Pagination selectListAndUser(Map<String, Object> params, Integer pageNo, Integer pageSize) {
		
		
		  Pagination pagination = new Pagination();
	        pagination.setPageNo(pageNo);
	        pagination.setPageSize(pageSize);
	        params.putAll(pagination.toMap());
	        int count = czjweixinvoucherMapper.selectListAndUserRows(params);
	        List<Map<String, Object>> list = czjweixinvoucherMapper.selectListAndUser(params);
	        pagination.setTotalCount(count);
	        pagination.setList(list);
	        return pagination;
	}

    public Czjweixinvoucher queryByOrderno(String orderno) {
        return czjweixinvoucherMapper.queryByOrderno(orderno);
    }
}
